<template>

  <div class="collection-main" v-if="state.collectionList.length>0">
    <div  class="card" v-for="c in state.collectionList" :key="c" >

      <el-image :src="c.video.videoCover" style="border-radius: 5px" @click="router.push(`/play/${c.videoCode}`)"/>
      <p class="video-name" @click="router.push(`/play/${c.videoCode}`)">{{c.video.videoName}}</p>
      <p class="collect-time">{{c.createTime}}
        <el-dropdown>
        <el-icon><More /></el-icon>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="cancelCollect(c.videoCode)">取消收藏</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </p>
    </div>

  </div>
  <div v-else style="width: 100%;height: 95%;display: flex;justify-content: center;align-items: center">
    <el-empty  description="还未收藏任何视频哦！" />
  </div>
  <el-pagination v-if="state.collectionList.length>0" hide-on-single-page layout="prev, pager, next" :total="state.total" style="width: 100%;display: flex;justify-content: center;margin-top: 10px" />

</template>

<script setup>
import {onMounted, reactive} from "vue";
import CollectionApi from "@/api/CollectionApi.js";
import {useRouter} from "vue-router";
const router = useRouter()
const state = reactive({
  collectionList:[],
  queryDto:{
    pageNum:1,
    size:10

  },
  total:0
})

const getCollectionList = ()=>{
  CollectionApi.getCollectList(state.queryDto).then(res=>{
    state.collectionList = res.data.data
    state.total = res.data.total
  })
}
onMounted(()=>{
  getCollectionList()
})

const cancelCollect = (videoCode)=>{
  CollectionApi.doCollect({videoCode:videoCode,status:2}).then(res=>{
    state.queryDto.pageNum=1
    getCollectionList()
  })
}

</script>

<style scoped lang="less">
.collection-main{
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 10px;
  height: 95%;
  overflow-y: scroll;
  scrollbar-width:none;
  border-radius: 8px;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.72);

}
.card{
  max-height: 350px;
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.72);
  cursor: pointer;
}
.collect-time{
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}




</style>